MacroScript ExportMeshText category:"Fili"
( 
	fn GetGeometry o = (Superclassof o == Geometryclass and classof o != TargetObject ) 
	obj = pickobject filter:GetGeometry 

	if isValidNode obj then 
	( 

		tmesh = snapshotAsMesh obj 
		out_name = GetSaveFileName() 

		if out_name != undefined then 
  		( 
			out_file = createfile out_name 

    			num_verts = tmesh.numverts 
    			num_tverts = tmesh.numtverts
    			num_faces = tmesh.numfaces 

    			format "% % %\n" num_verts num_tverts num_faces to:out_file 
	
    			for v = 1 to num_verts do 
    			(
				vert = getVert tmesh v
				px = vert.x
				py = vert.y
				pz = vert.z
      				format "% % %\n" px py pz to:out_file 
			)


    			format "\n" to:out_file 
    			for v = 1 to num_tverts do 
    			(
				tvert = getTVert tmesh v
				tx = tvert.x
				ty = tvert.y
      				format "% %\n" tx ty to:out_file 
			)

    			format "\n" to:out_file 

    			for f = 1 to num_faces do 
    			( 
      				face = getFace tmesh f
				tface = getTVFace tmesh f
				normals = meshop.getFaceRNormals tmesh f

				v1 = (face.x - 1) as integer
				v2 = (face.y - 1) as integer
				v3 = (face.z - 1) as integer

				tv1 = (tface.x - 1) as integer
				tv2 = (tface.y - 1) as integer
				tv3 = (tface.z - 1) as integer


      				format "[% % %] [% % %]" v1 v2 v3 tv1 tv2 tv3 to:out_file 
				for i=1 to 3 do
				(
					nx = normals[i].x
					ny = normals[i].y
					nz = normals[i].z
					format "% [% % %] " i nx ny nz to:out_file
				)
				format "\n" to:out_file 
    			) 

    			close out_file 
    			edit out_name 
  		) 
	)
) 
